﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;

namespace WPFTestSolution.Pages {
    public partial class _41_Image_Page : Page {
        
        /**
         * https://www.bilibili.com/video/BV1bV411A7Eq?p=41
         * 041-Image图像控件
         * https://www.wpfsoft.com/2023/08/29/1457.html
         */
        public _41_Image_Page() {
            InitializeComponent();
            this.Title = "041-Image图像控件(: FrameworkElement)";
            
            /**
             * AppDomain.CurrentDomain.BaseDirectory:
             * C:\Users\Administrator\AppData\Local\Temp\.net\WPFTestSolution\Z8JilZnk+YxRjBRsFt1lRDoGJv_cq6o=\
             */
            string path0 = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images/ic_qq.png");
            Console.WriteLine($"patn0 = {path0}");
            if (System.IO.File.Exists(path0)) {
                this.Image_Local0.Source = new BitmapImage(new Uri(path0)); 
            } else {
                MessageBox.Show($"path0文件未找到: {path0}");
            }

            /**
             * Environment.CurrentDirectory: E:\workspace_cpp\WPFTestSolution\bin\Release\Publish\
             * if 打包成单个.exe文件, 这个目录对不上
             */
            //当前.exe对应目录
            var path1 = Environment.CurrentDirectory + "/Images/ic_qq.png";
            Console.WriteLine($"path1 = {path1}");
            if (System.IO.File.Exists(path1)) {
                BitmapFrame imageSource = BitmapFrame.Create(new Uri(path1), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
                this.Image_Local1.Source = imageSource; 
            } else {
                // MessageBox.Show($"path1文件未找到: {path1}");
                Console.WriteLine($"path1文件未找到: {path1}");
            }
        }
    }
}